def get_index_info_sql(database_type, source):
    v_sql = ""
    if database_type == 'openGauss' or database_type == 'gaussdb':
        v_sql = """
SELECT ''""" + source + """'' AS source
      ,n.nspname AS schema
      ,pg_get_userbyid(c.relowner) AS owner
      ,c.relname AS table_name
      ,c2.relname AS index_name
      ,REPLACE(pg_get_indexdef(i.indexrelid)
              ,'' USING btree''
              ,'''') || '';'' AS index_def
      ,CASE
         WHEN i.indisprimary THEN
          ''Y''
         ELSE
          ''N''
       END AS index_is_primary
      ,CASE
         WHEN i.indisunique THEN
          ''Y''
         ELSE
          ''N''
       END AS index_is_unique
      ,case
         when i.indexprs IS NULL
           then ARRAY_TO_STRING((SELECT array(
                         SELECT (select a.attname
                                   from pg_attribute a
                                  where a.attrelid = i.indrelid
                                    and a.attnum = val)
                           FROM unnest(i.indkey) as val
                             )),'','')
         else REGEXP_REPLACE(pg_get_indexdef(i.indexrelid)::text, ''^CREATE\s(UNIQUE\s)?INDEX\s([a-z0-9_]+)\sON\s([a-z0-9_]+)\sUSING\subtree\s\((.*)\)\sWITH\s.*$'', ''\4'')
       end as index_columns
      ,pg_get_expr(i.indpred
                  ,i.indrelid) AS where_condition
  FROM pg_index i
  JOIN pg_class c
    ON c.oid = i.indrelid
  JOIN pg_namespace n
    ON n.oid = c.relnamespace
  JOIN pg_class c2
    ON c2.oid = i.indexrelid
  LEFT JOIN pg_constraint con
    ON con.conindid = i.indexrelid
 WHERE c.relkind = ''r''
   AND n.nspname !~* ''^pg\_|dbe_pldeveloper|db4ai|adms_checkpoint''
   AND con.oid IS NULL
UNION ALL
SELECT ''""" + source + """'' AS source
      ,n.nspname AS SCHEMA
      ,pg_get_userbyid(c.relowner) AS owner
      ,c.relname AS table_name
      ,con.conname AS index_or_constraint_name
      ,''ALTER TABLE '' || quote_ident(n.nspname) || ''.'' ||
       quote_ident(c.relname) || '' ADD CONSTRAINT '' ||
       quote_ident(con.conname) || '' '' || pg_get_constraintdef(con.oid) || '';'' AS ddl
      ,CASE
         WHEN con.contype = ''p'' THEN
          ''Y''
         ELSE
          ''N''
       END AS is_primary
      ,CASE
         WHEN con.contype = ''u'' THEN
          ''Y''
         ELSE
          ''N''
       END AS is_unique
       ,ARRAY_TO_STRING((SELECT array(
                 SELECT (select a.attname
                           from pg_attribute a
                          where a.attrelid = con.conrelid
                            and a.attnum = val)
                   FROM unnest(con.conkey) as val
                     )),'','') as index_columns
           
      ,NULL AS where_condition
  FROM pg_constraint con
  JOIN pg_class c
    ON c.oid = con.conrelid
  JOIN pg_namespace n
    ON n.oid = c.relnamespace
 WHERE c.relkind = ''r''
   AND n.nspname !~* ''^pg\_|dbe_pldeveloper|db4ai|adms_checkpoint''
   AND con.contype IN (''p''
                      ,''u'')
 ORDER BY SCHEMA
         ,table_name
         ,index_name
        """
    elif database_type == 'PostgreSQL':
        v_sql = """
SELECT ''""" + source + """'' AS source
      ,n.nspname AS schema
      ,pg_get_userbyid(c.relowner) AS owner
      ,c.relname AS table_name
      ,c2.relname AS index_name
      ,REPLACE(pg_get_indexdef(i.indexrelid)
              ,'' USING btree''
              ,'''') || '';'' AS index_def
      ,CASE
         WHEN i.indisprimary THEN
          ''Y''
         ELSE
          ''N''
       END AS index_is_primary
      ,CASE
         WHEN i.indisunique THEN
          ''Y''
         ELSE
          ''N''
       END AS index_is_unique
      ,(SELECT array_to_string(array_agg(attname ORDER BY ordinality)
                              ,'','')
          FROM unnest(i.indkey) WITH ordinality k(attnum, ordinality)
          JOIN pg_attribute a
            ON a.attrelid = i.indrelid
           AND a.attnum = k.attnum) AS index_columns
      ,pg_get_expr(i.indpred
                  ,i.indrelid) AS where_condition
  FROM pg_index i
  JOIN pg_class c
    ON c.oid = i.indrelid
  JOIN pg_namespace n
    ON n.oid = c.relnamespace
  JOIN pg_class c2
    ON c2.oid = i.indexrelid
  LEFT JOIN pg_constraint con
    ON con.conindid = i.indexrelid
 WHERE c.relkind = ''r''
   AND n.nspname NOT LIKE ''pg_%''
   AND con.oid IS NULL
UNION ALL
SELECT ''""" + source + """'' AS SOURCE
      ,n.nspname AS SCHEMA
      ,pg_get_userbyid(c.relowner) AS owner
      ,c.relname AS table_name
      ,con.conname AS index_or_constraint_name
      ,''ALTER TABLE '' || quote_ident(n.nspname) || ''.'' ||
       quote_ident(c.relname) || '' ADD CONSTRAINT '' ||
       quote_ident(con.conname) || '' '' || pg_get_constraintdef(con.oid) || '';'' AS ddl
      ,CASE
         WHEN con.contype = ''p'' THEN
          ''Y''
         ELSE
          ''N''
       END AS is_primary
      ,CASE
         WHEN con.contype = ''u'' THEN
          ''Y''
         ELSE
          ''N''
       END AS is_unique
      ,(SELECT array_to_string(array_agg(attname ORDER BY ordinality)
                              ,'','')
          FROM unnest(con.conkey) WITH ordinality k(attnum, ordinality)
          JOIN pg_attribute a
            ON a.attrelid = con.conrelid
           AND a.attnum = k.attnum) AS columns
      ,NULL AS where_condition
  FROM pg_constraint con
  JOIN pg_class c
    ON c.oid = con.conrelid
  JOIN pg_namespace n
    ON n.oid = c.relnamespace
 WHERE c.relkind = ''r''
   AND n.nspname NOT LIKE ''pg_%''
   AND con.contype IN (''p''
                      ,''u'')
 ORDER BY SCHEMA
         ,table_name
         ,index_name
        """
    else:
        print("get_index_info_service.py -- 未知的数据库类型！")
    return v_sql
